package com.example.book.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class AspectDemo {
    @Pointcut("execution(* com.example.book.controller.*.*(..))")
    public void pt(){

    }
    @Before("pt()")
    public void doBefore(){
        log.info("AspectDemo 执行doBefore...");
    }

    @After("pt()")
    public void doAfter(){
        log.info("AspectDemo 执行doAfter...");
    }

    @AfterReturning("pt()")
    public void AfterReturning(){
        log.info("AspectDemo 执行AfterReturning...");
    }

    @AfterThrowing("pt()")
    public void AfterThrowing(){
        log.info("AspectDemo 执行AfterThrowing...");
    }
    @Around("pt()")
    public Object doAround(ProceedingJoinPoint jt){
        log.info("around 前处理");
        Object proceed = null;
        try {
            proceed = jt.proceed();
        } catch (Throwable e) {
            log.error("around 发生异常");
        }
        log.info("around 后处理");
        //必须要有返回结果
        return proceed;

    }
}
